﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NetDisk_WebService
{
    public partial class DownloadFileSingle : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["SrcPath"] != null)
            {
                string SrcPath = Request.QueryString["SrcPath"].ToString();
                SendFile(SrcPath);
            }
        }

        private void SendFile(string SrcPath)
        {
            System.IO.FileInfo file = new System.IO.FileInfo(SrcPath);
            Response.Clear();
            Response.Charset = "utf-8";//设置输出的编码
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            // 添加头信息，为"文件下载/另存为"对话框指定默认文件名   
            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
            // 添加头信息，指定文件大小，让浏览器能够显示下载进度   
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/msword";
            // 把文件流发送到客户端   
            Response.WriteFile(file.FullName);
            Response.End();

        }



    }
}